#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
using namespace std;

int n;
const int maxn = 1e5 + 1;

int a[maxn];
int b[maxn];
int mp[maxn];
int f[maxn];

// dp[i][j]表示a的前i位和b的前j位的公共子序列

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        mp[a[i]] = i; //进行映射
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
    }
    int len = 0;

    for(int i=1;i<=n;i++){
        if(mp[b[i]] >f[len-1]){
            f[len++] = mp[b[i]];
        }
        else f[lower_bound(f,f+len,mp[b[i]])-f] = mp[b[i]];
    }
    cout << len <<endl;
    //system("pause");
    return 0;

}